home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers1.zip / DECOUT.ASM < prev    next >
Assembly Source File  |  1992-01-17  |  878b  |  46 lines

  1. ;put into the public domain by Russell Nelson, nelson@crynwr.com
  2.  
  3.     public    decout
  4. decout:
  5.     mov    si,ax            ;get the number where we want it.
  6.     mov    di,dx
  7.     or    ax,dx            ;is the number zero?
  8.     jne    decout_nonzero
  9.     mov    al,'0'            ;yes - easier to just print it, than
  10.     jmp    chrout            ;  to eliminate all but the last zero.
  11. decout_nonzero:
  12.  
  13.     xor    ax,ax            ;start with all zeroes in al,bx,bp
  14.     mov    bx,ax
  15.     mov    bp,ax
  16.  
  17.     mov    cx,32            ;32 bits in two 16 bit registers.
  18. decout_1:
  19.     shl    si,1
  20.     rcl    di,1
  21.     xchg    bp,ax
  22.     call    addbit
  23.     xchg    bp,ax
  24.     xchg    bx,ax
  25.     call    addbit
  26.     xchg    bx,ax
  27.     adc    al,al
  28.     daa
  29.     loop    decout_1
  30.  
  31.     mov    cl,'0'            ;prepare to eliminate leading zeroes.
  32.     call    byteout            ;output the first two.
  33.     mov    ax,bx            ;output the next four
  34.     call    wordout            ;output the next four
  35.     mov    ax,bp
  36.     jmp    wordout
  37.  
  38. addbit:    adc    al,al
  39.     daa
  40.     xchg    al,ah
  41.     adc    al,al
  42.     daa
  43.     xchg    al,ah
  44.     ret
  45.  
  46.